#!/usr/bin/env ruby
class User
    def initialize name, home
        @name, @home = name, home
    end
    def to_s
        "{ #@name, #@home, #@homeusage }"
    end
    attr_accessor :name, :home, :homeusage
end
hdirs = Kernel.open('|ls /home/').select do |item|
    item = item.chomp
    item != 'lost+found' and File.directory?("/home/#{item}") and not item.start_with?('.')
end

users = []
hdirs = hdirs.map do |h| h.chomp end
hdirs.each do |h|
    name, home = h, "/home/#{h}"
    users << User.new(name, home)
end

require 'thread'
threads = []
users.each do |user|
    threads << Thread.new do
        user.homeusage = Kernel.open("|du -sh #{user.home}").readline.split[0]
    end
end
threads.each do |t| t.join end
users.each do |u| p u.to_s end
